package ui.components;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.SwingConstants;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

/**
 * Un slider avec un label.
 * 
 * @author sebastien
 */
public class JSliderLabel extends JPanel {

	// Constants
	private static final long serialVersionUID = 1L;
	private static final int DEFAULT_SLIDER_VALUE = 50;

	// Fields
	/** Le label */
	private JLabel label;
	/** Le slider */
	private JSlider slider;
	/** La valeur du slider */
	private JLabel value;

	// Constructors
	public JSliderLabel() {

	}

	// Accessors
	public JSliderLabel(String string) {
		value = new JLabel("" + DEFAULT_SLIDER_VALUE);

		label = new JLabel(string);
		slider = new JSlider(SwingConstants.HORIZONTAL, 0, 100, Integer.valueOf(value.getText()));
		slider.addChangeListener(new ChangeListener() {
			public void stateChanged(ChangeEvent e) {
				value.setText("" + slider.getValue());
			}
		});
		this.add(label);
		this.add(slider);
		this.add(value);
	}

	public JLabel getLabel() {
		return label;
	}

	public JSlider getSlider() {
		return slider;
	}

	public JLabel getValue() {
		return value;
	}

	public void setLabel(JLabel label) {
		this.label = label;
	}

	public void setSlider(JSlider slider) {
		this.slider = slider;
	}

	public void setValue(JLabel value) {
		this.value = value;
	}

}